<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
<!-- Copyright 1997 The Open Group, All Rights Reserved -->
<title>getrlimit</title>
</head><body bgcolor=white>
<center>
<font size=2>
The Single UNIX &reg; Specification, Version 2<br>
Copyright &copy; 1997 The Open Group

</font></center><hr size=2 noshade>
<h4><a name = "tag_000_005_713">&nbsp;</a>NAME</h4><blockquote>
getrlimit, setrlimit - control maximum resource consumption
</blockquote><h4><a name = "tag_000_005_714">&nbsp;</a>SYNOPSIS</h4><blockquote>
<pre><code>

#include &lt;<a href="sysresource.h.html">sys/resource.h</a>&gt;

int getrlimit(int <i>resource</i>, struct rlimit *<i>rlp</i>);
int setrlimit(int <i>resource</i>, const struct rlimit *<i>rlp</i>);
</code>
</pre>
</blockquote><h4><a name = "tag_000_005_715">&nbsp;</a>DESCRIPTION</h4><blockquote>
Limits on the consumption of a variety of resources by the calling process
may be obtained with
<i>getrlimit()</i>
and set with
<i>setrlimit()</i>.
<p>
Each call to either
<i>getrlimit()</i>
or
<i>setrlimit()</i>
identifies a specific resource to be operated upon as well as a resource
limit.
A resource limit is represented by an
<b>rlimit</b>
structure.  The
<b>rlim_cur</b>
member specifies the current or soft limit and the
<b>rlim_max</b>
member specifies the maximum or hard limit.  Soft limits may be changed by
a process to any value that is less than or equal to the hard limit.  A
process may (irreversibly) lower its hard limit to any value that is greater
than or equal to the soft limit.  Only a process with appropriate privileges
can raise a hard limit.  Both hard and soft limits can be changed in a single
call to
<i>setrlimit()</i>
subject to the constraints described above.
<p>
The value RLIM_INFINITY, defined in
<i><a href="sysresource.h.html">&lt;sys/resource.h&gt;</a></i>,
is considered to be larger than any other limit value.  If a call to
<i>getrlimit()</i>
returns RLIM_INFINITY for a resource, it means the implementation does not
enforce limits on that resource.
Specifying RLIM_INFINITY as any resource limit value on a successful call to
<i>setrlimit()</i>
inhibits enforcement of that resource limit.
<p>
The following resources are defined:
<dl compact>

<dt>RLIMIT_CORE<dd>
This is the maximum size of a core file in bytes that may be created by a
process.  A limit of 0 will prevent the creation of a core file.  If this
limit is exceeded, the writing of a core file will terminate at this size.

<dt>RLIMIT_CPU<dd>
This is the maximum amount of CPU time in seconds used by a process.
If this limit is exceeded, SIGXCPU is generated for the process.  If the
process is catching or ignoring SIGXCPU, or all threads belonging to
that process are blocking SIGXCPU, the behaviour is unspecified.

<dt>RLIMIT_DATA<dd>
This is the maximum size of a process' data segment in bytes.
If this limit is exceeded, the
<i><a href="brk.html">brk()</a></i>,
<i><a href="malloc.html">malloc()</a></i>
and
<i><a href="sbrk.html">sbrk()</a></i>
functions will fail with <i>errno</i> set to [ENOMEM].

<dt>RLIMIT_FSIZE<dd>
This is the maximum size of a file in bytes that may be created by a process.
If a write or truncate operation would cause this limit to be exceeded,
SIGXFSZ is generated for the thread.  If the thread is blocking, or
the process is catching or ignoring SIGXFSZ, continued attempts to
increase the size of a file from end-of-file to beyond the limit
will fail with <i>errno</i> set to [EFBIG].

<dt>RLIMIT_NOFILE<dd>

This is a number one greater than the maximum value that the system may
assign to a newly-created descriptor.  If this limit is exceeded,
functions that allocate new file descriptors may fail
with errno set to [EMFILE].  This limit constrains the number of
file descriptors that a process may allocate.

<dt>RLIMIT_STACK<dd>
This is the maximum size of a process' stack in bytes.  The implementation
will not automatically grow the stack beyond this limit.  If this limit is
exceeded, SIGSEGV is generated for the thread.  If the thread is blocking
SIGSEGV, or the process is ignoring or catching SIGSEGV and has not made
arrangements to use an alternate stack, the disposition of SIGSEGV will be set
to SIG_DFL before it is generated.

<dt>RLIMIT_AS<dd>
This is the maximum size of a process' total available memory, in
bytes.  If this limit is exceeded, the
<i><a href="brk.html">brk()</a></i>,
<i><a href="malloc.html">malloc()</a></i>,
<i><a href="mmap.html">mmap()</a></i>
and
<i><a href="sbrk.html">sbrk()</a></i>
functions will fail with <i>errno</i> set to [ENOMEM].  In addition, the
automatic stack growth will fail with the effects outlined above.

</dl>
<p>
When using the 
<i>getrlimit()</i>
function, if a resource limit can be
represented correctly in an object of type 
<b>rlim_t</b>
then its representation is returned; otherwise if the value of the resource
limit is equal to that of the corresponding saved hard limit, the value
returned is RLIM_SAVED_MAX; otherwise the value returned is
RLIM_SAVED_CUR. 
<p>
When using the 
<i>setrlimit()</i>
function, if the requested new limit is
RLIM_INFINITY the new limit will be &quot;no limit&quot;; otherwise if the
requested new limit is RLIM_SAVED_MAX, the new limit will be the
corresponding saved hard limit; otherwise if the requested new limit
is RLIM_SAVED_CUR, the new limit will be the corresponding saved soft
limit; otherwise the new limit will be the requested value. In
addition, if the corresponding saved limit can be represented
correctly in an object of type 
<b>rlim_t</b>
then it will be overwritten with
the new limit. 
<p>
The result of setting a limit to RLIM_SAVED_MAX or RLIM_SAVED_CUR is
unspecified unless a previous call to 
<i>getrlimit()</i>
returned that value
as the soft or hard limit for the corresponding resource limit. 
<p>
The determination of whether a limit can be correctly represented in
an object of type 
<b>rlim_t</b>
is implementation-dependent. For example,
some implementations permit a limit whose value is greater than
RLIM_INFINITY and others do not. 
<p>
The <i>exec</i> family of functions also cause resource limits to be 
saved. 
</blockquote><h4><a name = "tag_000_005_716">&nbsp;</a>RETURN VALUE</h4><blockquote>
Upon successful completion,
<i>getrlimit()</i>
and
<i>setrlimit()</i>
return 0.  Otherwise, these functions return -1 and set
<i>errno</i> to indicate the error.
</blockquote><h4><a name = "tag_000_005_717">&nbsp;</a>ERRORS</h4><blockquote>
The
<i>getrlimit()</i>
and
<i>setrlimit()</i>
functions will fail if:
<dl compact>

<dt>[EINVAL]<dd>
An invalid <i>resource</i> was specified; or in a
<i>setrlimit()</i>
call, the new <b>rlim_cur</b> exceeds the new <b>rlim_max</b>.

<dt>[EPERM]<dd>
The limit specified to
<i>setrlimit()</i>
would have raised the maximum limit value, and the calling process does not
have appropriate privileges.

</dl>
<p>
The
<i>setrlimit()</i>
function may fail if:
<dl compact>

<dt>[EINVAL]<dd>
The limit specified cannot be lowered because current usage is already higher
than the limit.

</dl>
</blockquote><h4><a name = "tag_000_005_718">&nbsp;</a>EXAMPLES</h4><blockquote>
None.
</blockquote><h4><a name = "tag_000_005_719">&nbsp;</a>APPLICATION USAGE</h4><blockquote>
If a process attempts to set the hard limit or soft limit for
RLIMIT_NOFILE to less than the value of _POSIX_OPEN_MAX from
<i><a href="limits.h.html">&lt;limits.h&gt;</a></i>,
unexpected behaviour may occur.
</blockquote><h4><a name = "tag_000_005_720">&nbsp;</a>FUTURE DIRECTIONS</h4><blockquote>
None.
</blockquote><h4><a name = "tag_000_005_721">&nbsp;</a>SEE ALSO</h4><blockquote>
<i><a href="brk.html">brk()</a></i>,
<i><a href="exec.html">exec</a></i>,
<i><a href="fork.html">fork()</a></i>,
<i><a href="malloc.html">malloc()</a></i>,
<i><a href="open.html">open()</a></i>,
<i><a href="sbrk.html">sbrk()</a></i>,
<i><a href="sigaltstack.html">sigaltstack()</a></i>,
<i><a href="sysconf.html">sysconf()</a></i>,
<i><a href="ulimit.html">ulimit()</a></i>,
<i><a href="stropts.h.html">&lt;stropts.h&gt;</a></i>,
<i><a href="sysresource.h.html">&lt;sys/resource.h&gt;</a></i>.
</blockquote><hr size=2 noshade>
<center><font size=2>
UNIX &reg; is a registered Trademark of The Open Group.<br>
Copyright &copy; 1997 The Open Group
<br> [ <a href="../index.html">Main Index</a> | <a href="../xshix.html">XSH</a> | <a href="../xcuix.html">XCU</a> | <a href="../xbdix.html">XBD</a> | <a href="../cursesix.html">XCURSES</a> | <a href="../xnsix.html">XNS</a> ]

</font></center><hr size=2 noshade>
</body></html>
